﻿using System;
using System.Collections.Generic;

using NUnit.Framework;

using VidoopSecure;
using VidoopSecureExtensionMethods;

namespace TestVidoopSecure
{
    [TestFixture]
    public class TestSmsotpService : BaseTest
    {
        [TestFixtureSetUp]
        public override void SetUp()
        {
            base.SetUp();
        }

        [TestFixtureTearDown]
        public override void TearDown()
        {
            base.TearDown();
        }

        [Test]
        public void Test_GetService()
        {
            Service smsotpService = Manager.GetService(
                "smsotp", CurrentSite);
            Assert.IsNotNull(smsotpService);
        }

        [Test]
        public void Test_NewSmsotp()
        {
            SmsotpService service = (SmsotpService)Manager.GetService(
                "smsotp", CurrentSite);
            Assert.IsNotNull(service);

            Random rand = new Random(DateTime.Now.Millisecond);
            string userId = RandomString(8,false);
            string phone = Settings.PhoneNumber;
            Smsotp smsotp = service.NewSmsotp(userId, phone);
            Assert.IsNotNull(smsotp);

            Assert.AreEqual(phone, smsotp.Phone);
            Assert.AreEqual("pending", smsotp.SendStatus);
            Assert.AreEqual("pending", smsotp.AuthenticationStatus);

            // Test the GET of the transaction status
            Smsotp smsotp2 = service.GetSmsotp(smsotp.Id);
            Assert.IsNotNull(smsotp2);

            Assert.AreEqual(phone, smsotp2.Phone);
            Assert.IsTrue("pending" == smsotp2.SendStatus ||
                          "success" == smsotp2.SendStatus);
            Assert.AreEqual("pending", smsotp2.AuthenticationStatus);
       }

        // In order to test this, you need a current SMS AND its code.
        // Since an SMS containing the code is sent to a phone, we 
        // don't have plumbing to get it and use the code here.
        // Instead, this testing has to be done manually.
        //
       // [Test]
       // public void Test_ValidateSmsotp()
       // {
       //     SmsotpService service = (SmsotpService)Manager.GetService(
       //         "smsotp", CurrentSite);
       //     Assert.IsNotNull(service);

       //     Smsotp smsotp = service.GetSmstop("7");
       //     Assert.IsNotNull(smsotp);

       //     string code = "267295";
       //     Assert.IsTrue(service.ValidateSmsotp(smsotp.Id, code));
       //}
    }
}
